/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package locusts.server.collisions;

import locusts.common.entities.Entity;
import locusts.common.entities.EntityData;
import locusts.common.entities.EntityDataList;

/**
 *
 * @author Hamish Morgan
 */
public class EatCropsCR extends EntityCRAdapter {

    private final EntityDataList data;

    public EatCropsCR(EntityDataList data) {
        this.data = data;
    }

    public void doCollision(Entity locust, Entity farm, double period) {

        EntityData farmD = data.get(farm);
        EntityData locustD = data.get(locust);

        double delta = 0.1;
        delta = Math.min(delta, farm.getEnergy() - farmD.getMinEnergy());
        delta = Math.min(delta, locustD.getMaxEnergy() - locust.getEnergy());

        if (delta > 0) {
            farm.setEnergy(farm.getEnergy() - delta);
            locust.setEnergy(locust.getEnergy() + delta);
            farm.setModified();
            locust.setModified();
        }


    }
}
